package com.hockeo.client.ui.views;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.Status;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.ui.Widget;
import com.hockeo.shared.VHUtil;

/**
 * Main view representing the application main window.
 *
 * @version $Id$
 * @author jjanke
 */
public class MainView extends Viewport implements IView
{
  private final static int MARGIN = 4;

  private BorderLayoutData d_dataTop;
  private BorderLayoutData d_dataLeft;
  private BorderLayoutData d_dataCenter;
  private ToolBar          d_toolBar;
  private Status           d_status;

  /**
   * Default parameterless constructor required by each view.
   */
  public MainView()
  {
    setLayout( new BorderLayout() );
    createStatusBar();
  }

  private void createStatusBar()
  {
    d_toolBar = new ToolBar();

    d_status = new Status();
    d_status.setText( VHUtil.constants().getAppName() + " v" + VHUtil.constants().getAppVersion() + " ("
        + VHUtil.constants().getAppBuildTimestamp() + ")" );

    d_toolBar.add( d_status );
    d_toolBar.add( new FillToolItem() );

    BorderLayoutData data = new BorderLayoutData( LayoutRegion.SOUTH, 24f );
    add( d_toolBar, data );
  }

  @Override
  public Widget getViewWidget()
  {
    return this;
  }

  public void setTopWidget( Widget w )
  {
    if ( d_dataTop == null )
      d_dataTop = new BorderLayoutData( LayoutRegion.NORTH, 26f );

    add( w, d_dataTop );
  }

  public void setLeftWidget( Widget w )
  {
    if ( d_dataLeft == null )
    {
      d_dataLeft = new BorderLayoutData( LayoutRegion.WEST, 270, 180, 320 );
      d_dataLeft.setMargins( new Margins( MARGIN, MARGIN, MARGIN, MARGIN ) );
      d_dataLeft.setCollapsible( true );
    }

    add( w, d_dataLeft );
  }

  public void setCenterWidget( Widget w )
  {
    if ( d_dataCenter == null )
    {
      d_dataCenter = new BorderLayoutData( LayoutRegion.WEST, 270, 180, 320 );
      d_dataCenter.setMargins( new Margins( MARGIN, MARGIN, MARGIN, 0 ) );
      d_dataCenter.setCollapsible( false );
    }

    add( w, d_dataCenter );
  }
}
